local skill = fk.CreateSkill{
  name = "tea__xifeng",
}
---@type TrigSkelSpec<TrigFunc>
local xifeng = {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skill.name) and target == player and player:usedSkillTimes(skill.name, Player.HistoryTurn) == 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    data.damage = 0
    local to = player
    if event == fk.DamageCaused then
      to = data.to
    end
    if #to:getCardIds("e") > 0 then
      local num = #to:getCardIds("e")
      room:obtainCard(to, to:getCardIds("e"), true, fk.ReasonPrey)
      if not to.dead then
        local cids = room:askToDiscard(to, {
          skill_name = skill.name,
          min_num = num,
          max_num = num,
          include_equip = true,
          cancelable = false,
          prompt = "#tea__xifeng-discard:::" .. tostring(num),
        })
        cids = table.filter(cids, function(id)
          return Fk:getCardById(id).trueName == "slash"
        end)
        if #cids > 0 and not player.dead then
          room:askToYiji(player, {
            targets = room.alive_players,
            min_num = 0,
            max_num = 999,
            skill_name = skill.name,
            cards = cids,
            expand_pile = cids,
            prompt = "#tea__xifeng-yiji",
          })
        end
      end
    end
    return true
  end,
}
skill:addEffect(fk.DamageCaused, xifeng)
skill:addEffect(fk.DamageInflicted, xifeng)
return skill